package org.pizza.nacos;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import org.pizza.nacos.loadBalancer.ServerListUpdateListener;
import org.pizza.nacos.loadBalancer.ServiceInstancesWatch;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.loadbalancer.cache.LoadBalancerCacheManager;
import org.springframework.cloud.loadbalancer.config.LoadBalancerCacheAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 高巍
 * RibbonAutoConfiguration.class,
 * @since 2020/11/30 10:04 上午
 */
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter({LoadBalancerCacheAutoConfiguration.class})
public class NacosLoadBalancerAutoConfiguration {

    @Bean
    public ServerListUpdateListener serverListUpdateListener(LoadBalancerCacheManager loadBalancerCacheManager){
        return new ServerListUpdateListener(loadBalancerCacheManager);
    }

    @Bean
    public ServiceInstancesWatch serviceInstancesWatch(NacosDiscoveryProperties nacosDiscoveryProperties, NacosServiceManager nacosServiceManager, DiscoveryClient discoveryClient ){
        return new ServiceInstancesWatch(nacosDiscoveryProperties,nacosServiceManager,discoveryClient);
    }
}
